<?php

class SitemenuModule extends fvModule {

	private $appName = 'frontend';
    private $appConfig = null;
	
    function __construct () {
        $moduleName = strtolower(substr(__CLASS__, 0, -6));

        parent::__construct(fvSite::$fvConfig->get("modules.{$moduleName}.smarty.template"), 
                            fvSite::$fvConfig->get("modules.{$moduleName}.smarty.compile"), 
                            fvSite::$Layoult);
                            
    	$this->appConfig = new fvConfig(fvSite::$fvConfig->get("path.application.{$this->appName}.config"));
        $this->appConfig->Load("modules.yml");
    }

    function showIndex() {
        $this->__assign('Sitemenus', SitemenuManager::getInstance()->getAll("lang='".fvSite::$fvSession->get("lang")."'", "menu_order asc"));
        return $this->__display('sitemenu_list.tpl');    
    }

    function showEdit() {
        $request = fvRequest::getInstance();
        if (!$Sitemenu = SitemenuManager::getInstance()->getByPk($request->getRequestParameter('id'))) {
            $Sitemenu = new Sitemenu();
        }
    	foreach ($this->appConfig->get("modules") as $moduleName => $module) {
            if (!$module['system'])
                $moduleList[$moduleName] = $module['name'];
        }
        $pager = new fvPager(SitemenuManager::getInstance());
        $StaticPages = StaticPagesManager::getInstance()->getAll("parent='' and lang='".fvSite::$fvSession->get("lang")."'");
        $this->__assign(array(
        	"StaticPages" => $StaticPages,
            'Sitemenu' => $Sitemenu,
        	"Modules" => $moduleList
        ));
        return $this->__display('sitemenu_edit.tpl');
    }
   
}

?>
